<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0 auto;
        }

        div {
            width: 200px;
            height: 200px;
        }
    </style>
</head>

<body>
    <!-- <div style="background-color:"></div> -->
    <script>
        function getRandColor(flag) {
            let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
            if (flag === 'true') {
                document.write(`<div style="background-color:#${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}"></div>`)
                console.log(`#${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}${arr[Math.floor(Math.random() * arr.length)]}`);

            }
            else {
                document.write(`<div style="background-color:rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})"></div>`)
                console.log(`rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`);

            }
        }
        let flag = prompt("输入true获取十六进制颜色，输入false获取rgb颜色")
        getRandColor(flag)

    </script>
</body>

</html>